package com.extension.company.common.utils;

import android.app.Activity;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;

/**
 * 友盟分享的工具类
 */
public class UShareUtils {

	private Activity context;

	private UShareUtils() {
	}

	private static UShareUtils instance;

	public static UShareUtils getinstance() {
		return UShareUtilsHolder.mUShareUtils;
	}

	public static class UShareUtilsHolder {
		private static final UShareUtils mUShareUtils = new UShareUtils();
	}

	public UShareUtils init(Activity context) {
		this.context = context;
		return UShareUtilsHolder.mUShareUtils;
	}

	/**
	 * 带面板分享
	 */
	public void ShareAction() {
		new ShareAction(context).withText("hello")
				.setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
				.setCallback(umShareListener)
				.open();
	}

	/**
	 * 不带面板分享
	 *
	 * @param platform
	 */
	public void ShareAction(SHARE_MEDIA platform) {
		new ShareAction(context)
				.setPlatform(platform)//传入平台
				.withText("hello")    //分享内容
				.setCallback(umShareListener)//回调监听器
				.share();
	}

	private UMShareListener umShareListener = new UMShareListener() {
		/**
		 * @descrption 分享开始的回调
		 * @param platform 平台类型
		 */
		@Override
		public void onStart(SHARE_MEDIA platform) {
		}

		/**
		 * @descrption 分享成功的回调
		 * @param platform 平台类型
		 */
		@Override
		public void onResult(SHARE_MEDIA platform) {
			Toast.makeText(context, "分享成功", Toast.LENGTH_LONG).show();
		}

		/**
		 * @descrption 分享失败的回调
		 * @param platform 平台类型
		 * @param t 错误原因
		 */
		@Override
		public void onError(SHARE_MEDIA platform, Throwable t) {
			Toast.makeText(context, "分享失败" + t.getMessage(), Toast.LENGTH_LONG).show();
		}

		/**
		 * @descrption 分享取消的回调
		 * @param platform 平台类型
		 */
		@Override
		public void onCancel(SHARE_MEDIA platform) {
			Toast.makeText(context, "分享取消", Toast.LENGTH_LONG).show();
		}
	};
}
